package cn.tedu.knows.auth.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TokenConfig {

    //定义JWT解密口令
    //这个口令用于区分不同项目的jwt令牌
    //只有口令正确才能解析jwt令牌
    private final String SIGNING_KEY = "pass";

    //向Spring 容器保存一个令牌生成器
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(accessTokenConverter());
    }

    //jwt令牌转换器
    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        //设置解密口令并返回
        converter.setSigningKey(SIGNING_KEY);
        return converter;
    }
}
